package cn.huihuo.weibo.controller;

import cn.huihuo.weibo.bean.waterfall.WaterFallBean;
import cn.huihuo.weibo.module.ProdComment;
import cn.huihuo.weibo.module.WaterFall;
import cn.jfinalbbs.common.BaseController;
import com.jfinal.plugin.activerecord.Page;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Dan
 * Created by zhengjunbo on 2015/10/12.
 */
public class WaterFallController extends BaseController {

    public void findWaterFall(){
        String pageStep = getPara("pageStep");
        String count = getPara("count");

        List<WaterFallBean> waterFallBeans = new ArrayList<>();
        Page<WaterFall> waterFalls = WaterFall.waterFall.findWaterFall(Integer.valueOf(pageStep), Integer.valueOf(count));
        for(WaterFall waterFall :waterFalls.getList()){
            WaterFallBean waterFallBean = new WaterFallBean();
            waterFallBean.setUserName(waterFall.getStr("nickname"));
            waterFallBean.setWaterFallAvatar(waterFall.getStr("avatar"));
            waterFallBean.setWaterFallPic(waterFall.getStr("outPath"));
            waterFallBean.setWaterFallDescription(waterFall.getStr("comm"));
            waterFallBean.setWaterFallTitle(waterFall.getStr("title"));
            waterFallBean.setWaterFallPrice(String.valueOf(waterFall.getDouble("price")));
            waterFallBean.setWaterFallUrl(String.valueOf(waterFall.getInt("commId")));
            waterFallBean.setWid(String.valueOf(waterFall.getInt("wtId")));
            Integer prodId = waterFall.getInt("prodId");
            List<ProdComment> prodCommentList = ProdComment.prodComment.findProductComment(String.valueOf(prodId));
            waterFallBean.setWaterFallShareCount(String.valueOf(prodCommentList.size()));
            waterFallBeans.add(waterFallBean);
        }
        renderJson(waterFallBeans);
    }
}
